﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Imaginecup.Recycling.Object;
using Imaginecup.recycling.Object;
using Microsoft.Xna.Framework.Graphics;
using Imaginecup.shareData;
using Imaginecup.recycling.Object.Item;
using Imaginecup.recycling.Stage;
using Imaginecup.util.Funtion;
using Imaginecup.recycling.Factory;
using Imaginecup.factory;
using Imaginecup.recycling.GameMan;

namespace Imaginecup.Recycling.GameMan
{
    public class GameManager 
    {
        public static int ObjectKey = 0;

        private Dictionary<int, IGameObject> m_ObjectList;
        
        public GameManager()
        {
            m_ObjectList = new Dictionary<int, IGameObject>();
        }

        public void AddObject(IGameObject obj)
        {
            if (obj != null)
            {
                obj.SetPrimaryNumber(ObjectKey);
                m_ObjectList.Add(ObjectKey++, obj);
            }
        }
        public void RemoveObject(int key)
        {
            if (m_ObjectList.ContainsKey(key))
            {
                m_ObjectList.Remove(key);
            }
        }
        public void RemoveAll()
        {
            m_ObjectList.Clear();
        }

        public void Draw(SpriteBatch spriteBatch, GameTime gametime)
        {
            foreach (IGameObject obj in m_ObjectList.Values)
            {
                obj.Draw(spriteBatch, gametime);
            }
        }

        public void Update(GameTime gameTime)
        {
            foreach (int number in m_ObjectList.Keys)
            {
                m_ObjectList[number].Update(gameTime);
            }
        }
    }
}
